package logic

import (
	"context"
	"fmt"
	"goods_srv/models/mysql"

	"goods_srv/goodssrv"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfoLogic) GoodsInfo(in *goodssrv.GoodsInfoRequest) (*goodssrv.GoodsInfoResponse, error) {
	// todo: add your logic here and delete this line
	var goods mysql.Goods
	err := goods.FindGoods(in.GoodsId)
	if err != nil {
		return nil, fmt.Errorf("该商品不存在")
	}
	return &goodssrv.GoodsInfoResponse{
		GoodsId:     int64(goods.ID),
		Title:       goods.Title,
		Cover:       goods.Cover,
		Price:       float32(goods.Price),
		SalesVolume: goods.SalesVolume,
		Stock:       goods.Stock,
		Status:      goods.Status,
	}, nil
}
